home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / acad / autolisp / dragon / dragon.lsp
Text File  |  1989-09-24  |  5KB  |  126 lines

  1. ;;; -*-  Mode: LISP -*- Syntax: AutoLISP (C) Benjamin Olasov 1988
  2. ;;;      Functions to generate recursively defined drawings.
  3.  
  4. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5. ;;; File: DRAGON.LSP Copyright (C) Benjamin Olasov    Graphic Systems, Inc. ;;;
  6. ;;; Inquiries:                                                              ;;;
  7. ;;;                                                                         ;;;
  8. ;;;     Benjamin Olasov                                                     ;;;
  9. ;;;     Graphic Systems, Inc.:                                              ;;;
  10. ;;;                                                                         ;;;
  11. ;;;                    New York, NY:   PH (212) 725-4617                    ;;;
  12. ;;;                    Cambridge, MA:  PH (617) 492-1148                    ;;;
  13. ;;;                    MCI-Mail:       GSI-NY   344-4003                    ;;;
  14. ;;;                    Arpanet:        olasov@cs.columbia.edu               ;;;
  15. ;;;                                                                         ;;;
  16. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  17.  
  18. ;; This program is provided 'as is' without warranty of any kind, either 
  19. ;; expressed or implied, including, but not limited to the implied warranties of
  20. ;; merchantability and fitness for a particular purpose.  The entire risk as to
  21. ;; the quality and performance of the program is with the user.  Should the 
  22. ;; program prove defective, the user assumes the entire cost of all necessary 
  23. ;; servicing, repair or correction. 
  24. ;; AutoLisp and AutoCad are registered trademarks of AutoDesk, Inc.
  25.  
  26.  
  27. (VMON)
  28. (GC)
  29. (TEXTSCR)
  30. (PROMPT "\nC:DRAGON and C:C-CURVE generate recursively defined drawings.")
  31.  
  32. ; Random number generator
  33. (DEFUN RAN ()
  34.        (SETQ SEED (IF SEED (REM (+ (* SEED 15625.7) 0.21137152) 1) 0.3171943)))
  35.  
  36. (DEFUN C:DEMO () 
  37.        (GRAPHSCR) 
  38.        (DEFUN *ERROR* (MSG)
  39.               (PRINC MSG))
  40.        (SETQ CEN (GETVAR "VIEWCTR")
  41.              HGT (GETVAR "VIEWSIZE")
  42.              DIST1 HGT)
  43.        (WHILE (/= 1 2)
  44.               (SETQ DIST2 (* (RAN) DIST1)
  45.                     DIST3 (* (RAN) DIST1)
  46.                     A1 (* (/ PI 2.0) (RAN))
  47.                     A2 (* (/ PI 2.0) (RAN))
  48.                     P1 (POLAR CEN A1 DIST2)
  49.                     P2 (POLAR CEN A2 DIST3)
  50.                     LENG (DISTANCE P1 P2)
  51.                     MIN-LENG (MAX (/ HGT 161.8) (/ LENG 160.0)) 
  52.                     ANGL (ANGLE P1 P2)
  53.                     LEVEL 0)
  54.            (DRAGON LENG ANGL (+ 0.0 1.0) MIN-LENG) 
  55.            (REDRAW))
  56. (PRINC))
  57.  
  58. (DEFUN PLOT-LINE (L A)
  59.        (GRDRAW BASE (POLAR BASE A L) LEVEL)
  60.        (SETQ BASE (POLAR BASE A L)))
  61.  
  62. (DEFUN C-CURVE (LEN ANG MIN-LEN)
  63.        (SETQ LEVEL (1+ LEVEL))
  64.        (PRINC "\nLevel ")
  65.        (PRINC LEVEL)
  66.        (COND ((< LEN MIN-LEN)
  67.               (PRINC "\nPLOT-LINE at level ")
  68.               (PRINC LEVEL)
  69.               (PLOT-LINE LEN ANG))
  70.              (T (C-CURVE (/ LEN (SQRT 2.0))
  71.                          (+ ANG (/ PI 4.0))
  72.                           MIN-LEN)
  73.                 (C-CURVE (/ LEN (SQRT 2.0))
  74.                          (- ANG (/ PI 4.0))
  75.                          MIN-LEN)))
  76.        (PROGN (SETQ LEVEL (1- LEVEL))
  77.               (PRINC "\nLevel ")
  78.               (PRINC LEVEL)))
  79.  
  80. (DEFUN C:C-CURVE (/ BASE PT2 ANGL MIN-LENG CURVE-VAR)
  81.        (GRAPHSCR)
  82.        (SETQ LENG (DISTANCE (SETQ BASE (GETPOINT "\nStarting point: "))
  83.                             (SETQ PT2 (GETPOINT BASE
  84.                                                "\nDigitize length/ angle: "))) 
  85.              ANGL (ANGLE BASE PT2) 
  86.              MIN-LENG (MAX (/ (GETVAR "VIEWSIZE") 100.0) (/ LENG 160.0)) 
  87.              LEVEL 0) 
  88.        (C-CURVE LENG ANGL MIN-LENG) 
  89.        (GETSTRING "\nPress Return to clear: ") 
  90.        (REDRAW))
  91.  
  92. (DEFUN DRAGON (LEN ANG SIGN MIN-LEN)
  93.        (SETQ LEVEL (1+ LEVEL))
  94.        (PRINC "\nLevel ")
  95.        (PRINC LEVEL)
  96.        (COND ((< LEN MIN-LEN)
  97.               (PRINC "\nPLOT-LINE called at level ")
  98.               (PRINC LEVEL)
  99.               (PLOT-LINE LEN ANG))
  100.              (T (DRAGON (/ LEN (SQRT 2.0))
  101.                          (+ ANG (* SIGN (/ PI 4.0)))
  102.                           +1.0 MIN-LEN)
  103.                 (DRAGON (/ LEN (SQRT 2.0))
  104.                          (- ANG (* SIGN (/ PI 4.0)))
  105.                          -1.0 MIN-LEN)))
  106.        (PROGN (SETQ LEVEL (1- LEVEL))
  107.               (PRINC "\nLevel ")
  108.               (PRINC LEVEL)))
  109.  
  110. (DEFUN C:DRAGON (/ BASE PT2 ANGL MIN-LENG CURVE-VAR) 
  111.        (GRAPHSCR) 
  112.        (SETQ LENG (DISTANCE (SETQ BASE (GETPOINT "\nStarting point: ")) 
  113.                             (SETQ PT2 (GETPOINT BASE 
  114.                                                 "\nDigitize length/ angle: "))) 
  115.               ANGL (ANGLE BASE PT2) 
  116.               MIN-LENG (MAX (/ (GETVAR "VIEWSIZE") 100.0) (/ LENG 160.0)) 
  117.               LEVEL 0) 
  118.        (DRAGON LENG ANGL (+ 0.0 1.0) MIN-LENG) 
  119.        (GETSTRING "\nPress RETURN to clear: ") 
  120.        (REDRAW))
  121.  
  122. (PROMPT "\n\nType DRAGON or C-CURVE to generate a recursively defined drawing.")
  123. (PRINC)
  124.  
  125.  
  126.